package com.bdzl.ecs.controller;

import com.bdzl.ecs.service.ContractOnlineSignrecService;
import com.bdzl.pub.controller.BaseController;
import com.bdzl.pub.entity.loan.ContractOnlineSignrecDO;
import com.bdzl.pub.util.param.PageUtils;
import com.bdzl.pub.util.param.Query;
import com.bdzl.pub.util.param.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 电子合同签署记录表
 *
 * @author yangyicai
 * @email yangyicai@foxmail.com
 * @date 2021-03-23 14:00:08
 */

@Controller
@RequestMapping("/bdzl/contractOnlineSignrec")
public class ContractOnlineSignrecController extends BaseController {
	@Autowired
	private ContractOnlineSignrecService contractOnlineSignrecService;

	@GetMapping()
	String ContractOnlineSignrec(){
	    return "bdzl/contractOnlineSignrec/contractOnlineSignrec";
	}

	@ResponseBody
	@PostMapping("/list")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<ContractOnlineSignrecDO> contractOnlineSignrecList = contractOnlineSignrecService.list(query);
		int total = contractOnlineSignrecService.count(query);
		PageUtils pageUtils = new PageUtils(contractOnlineSignrecList, total);
		return pageUtils;
	}

	@GetMapping("/add")
	String add(){
	    return "bdzl/contractOnlineSignrec/add";
	}

	@GetMapping("/edit/{cosId}")
	String edit(@PathVariable("cosId") Integer cosId,Model model){
		ContractOnlineSignrecDO contractOnlineSignrec = contractOnlineSignrecService.get(cosId);
		model.addAttribute("contractOnlineSignrec", contractOnlineSignrec);
	    return "bdzl/contractOnlineSignrec/edit";
	}

	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	public R save( ContractOnlineSignrecDO contractOnlineSignrec){
		if(contractOnlineSignrecService.save(contractOnlineSignrec)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	public R update( ContractOnlineSignrecDO contractOnlineSignrec){
		contractOnlineSignrecService.update(contractOnlineSignrec);
		return R.ok();
	}

	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	public R remove( Integer cosId){
		if(contractOnlineSignrecService.remove(cosId)>0){
		return R.ok();
		}
		return R.error();
	}

	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	public R remove(@RequestParam("ids[]") Integer[] cosIds){
		contractOnlineSignrecService.batchRemove(cosIds);
		return R.ok();
	}
	/**
	 * @Description: TODO 根据订单号查询已签署的人数
	 * @param odrNo 订单号
	 * @return: int
	 * @Author: Ming
	 * @Date: 2021/5/26 18:53
	 */
	@ResponseBody
	@PostMapping("/listByCosOdr")
	public Integer listByCosOdr(@RequestParam("odrNo") String odrNo){
		return contractOnlineSignrecService.listByCosOdr(odrNo);
	}
}
